package com.lj.tools;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

public class ReadDBMSlProperty {
	private String filePath = "rmdbsconfig" + File.separator
			+ "rmdbsConfig.property";

	/**
	 *  这里是拼凑出来的路径
	 * @param filePath
	 * @return
	 */
	private String getPath(String filePath) {
		String basePath = System.getProperty("user.dir");
		// 拼凑出资源路径
		basePath = basePath + File.separator + "target" + File.separator
				+ "classes" + File.separator;
		String togetherPath = basePath + filePath;
		Path path = Paths.get(togetherPath);
		String result = path.toString();

		return result;
	}

	/**
	 * 
	 * @param property
	 * @return
	 */
	public String getPropertyByClassLoader(String property) {

		ClassLoader classLoader = getClass().getClassLoader();
		Properties pro = new Properties();
		try {
			InputStream in = classLoader.getResourceAsStream(filePath);

			pro.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String model = pro.getProperty(property).trim();
		return model;

	}
	
	
	

	public String getPropertyByPath(String property) {

		String path = getPath(filePath);
		System.out.println("path:" + path);
		Properties pro = new Properties();

		try {
			InputStream in = new FileInputStream(path);

			pro.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String model = pro.getProperty(property).trim();
		return model;

	}

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ReadDBMSlProperty test = new ReadDBMSlProperty();
		System.out.println(test.getPropertyByClassLoader("url"));
		// System.out.println(ReadDBMSlProperty.getPropertyMax_select_count());
	}

}
